package com.eric.enderslastgame;

import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Log;

public class Human {

	private static final String TAG = Human.class.getSimpleName();

	private final int VELOCITY = 2;

	private Bitmap bitmap, miniBitmap;

	private int x, y; // Position
	private int dx, dy; // Movement increments
	private int width, height; // Image properties
	private boolean visible;

	public boolean incoming; // True indicates the set of Buggers paired with
								// this Human is being generated

	public Human(Bitmap bitmap, Bitmap miniBitmap, int xInitial, int yInitial) {
		x = xInitial;
		y = yInitial;

		visible = true;
		incoming = false;

		this.bitmap = bitmap;
		this.miniBitmap = miniBitmap;

		width = bitmap.getWidth();
		Log.d(TAG, "Human Bitmap Width is " + width);
		height = bitmap.getHeight();
		Log.d(TAG, "Human Bitmap Height is " + height);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public Rect getRect() {
		return new Rect(x, y, x + width, y + height);
	}

	public Bitmap getBitmap() {
		return bitmap;
	}
	
	public Bitmap getMiniBitmap() {
		return miniBitmap;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public void setBitmap(Bitmap bitmap) {
		width = bitmap.getWidth();
		Log.d(TAG, "Human Width Bitmap Reset to " + width);
		height = bitmap.getHeight();
		Log.d(TAG, "Human Height Bitmap reset to " + height);
		this.bitmap = bitmap;
	}
	
	public void move() {
		x += dx;
		y += dy;

		if (x < 1) {
			x = 1;
		} else if ((x + width) > EndersGamePanel.panelWidth) {
			x = EndersGamePanel.panelWidth - width;
		}

		if (y < 1) {
			y = 1;
		} else if ((y + height) > (int) (EndersGamePanel.panelHeight * EndersGamePanel.BOARD_HEIGHT_FRACTION)) {
			y = (int) (EndersGamePanel.panelHeight * EndersGamePanel.BOARD_HEIGHT_FRACTION)
					- height;
		}
	}
}
